package com.geccocrawler.gecco.demo.fang;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.annotation.*;
import com.geccocrawler.gecco.request.HttpGetRequest;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.spider.HtmlBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 抽离 on 2017/5/24 0024.
 */
@Gecco(matchUrl = "http://esf.xm.fang.com/housing/{region}__0_0_0_0_{page}_0_0/", pipelines={"consolePipeline", "fangNextPipeline"})
public class Fang implements HtmlBean{

    @Request
    private HttpRequest request;

    @RequestParameter
    private String region;

    @RequestParameter
    private String page;

    @Text
    @HtmlField(cssPath = ".plotTit")
    private List<String> section;

    @Text
    @HtmlField(cssPath = ".sellOrRenthy>li:eq(0)>a")
    private List<String> sellCount;

    @Href
    @HtmlField(cssPath = "#PageControl1_hlk_next")
    private String nextUrl;

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public HttpRequest getRequest() {
        return request;
    }

    public void setRequest(HttpRequest request) {
        this.request = request;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public List<String> getSection() {
        return section;
    }

    public void setSection(List<String> section) {
        this.section = section;
    }

    public List<String> getSellCount() {
        return sellCount;
    }

    public void setSellCount(List<String> sellCount) {
        this.sellCount = sellCount;
    }

    public String getNextUrl() {
        return nextUrl;
    }

    public void setNextUrl(String nextUrl) {
        this.nextUrl = nextUrl;
    }

    public static void main(String[] args){
        List<String> urls = new ArrayList<>();
        List<HttpRequest> requests = new ArrayList<>();
        for(int j = 350; j < 356; j++) {
                HttpGetRequest httpGetRequest = new HttpGetRequest("http://esf.xm.fang.com/housing/" + j + "__0_0_0_0_1_0_0/");
                requests.add(httpGetRequest);
        }
        GeccoEngine.create().classpath("com.geccocrawler.gecco.demo.fang").thread(100).start(requests).run();
    }
}
